package com.ls.demo.http.service.impl;

import com.google.gson.Gson;
import com.ls.demo.bean.Command;
import com.ls.demo.bean.RoomBoxInfo;
import com.ls.demo.bean.SwitchCommand;
import com.ls.demo.enums.MessageAttrEnum;
import com.ls.demo.http.service.DownloadService;
import lombok.extern.java.Log;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liShan
 * @date 2019/9/4 22:56
 * @see MessageAttrEnum
 */
@Service("downloadSwitchServiceImpl_40")
@Log
public class DownloadSwitchServiceImpl  implements DownloadService {

    @Override
    public String execute(String str, Command command) {
        Gson gson = new Gson();
        SwitchCommand c = gson.fromJson(str, SwitchCommand.class);
        log.info(c.toString());
        RoomBoxInfo boxInfo = c.getBoxInfo();
        c.assCommand(command);
        List<String> datas = new ArrayList<>();
        datas.add(Integer.toHexString(c.getEqu()));
        datas.add(Integer.toHexString(c.getHandle()));
        short val1 = (short )1;
        short val2 = (short )2;
        if (val1 == c.getHandle() || val2 == c.getHandle()){
            datas.add(Integer.toHexString(c.getDelayTime()));
        }
        command.setDataList(datas);
        return boxInfo.getBoxId();
    }
}
